home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / RESTOOLS.C < prev    next >
Text File  |  1992-12-02  |  10KB  |  413 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  *
  55.  *
  56.  *    dumpr     - resource decompiler : RMAKER FORMAT
  57.  *    dumpr [options] [files]
  58.  *
  59.  *
  60.  *    IN PROGRESS
  61.  *
  62.  *    Resource command module
  63.  *
  64.  *    maker     - resource compiler : RMAKER FORMAT
  65.  *    maker [options] [files]
  66.  *
  67.  *
  68.  */
  69.  
  70. #include    <ResourceMgr.h>
  71.  
  72. #include    "SystemPub.h"
  73. #include    "Proc.h"
  74. #include    "ShellPub.h"
  75. #include    "Path.h"
  76.  
  77. /*******************************************************************
  78.  *
  79.  *    Function DUMPR
  80.  *
  81.  *    PathName Callback function
  82.  *
  83.  *    usage DUMPR [options] [names]    
  84.  *
  85.  *
  86.  *******************************************************************/
  87.  
  88. char         dumpResName[ 64 ];
  89.  
  90. #define        dumprResType    (**MyShell).Proc[ProcID].long0
  91. #define        dumprSize        (**MyShell).Proc[ProcID].long1
  92. #define        dumprIDStart    (**MyShell).Proc[ProcID].int0
  93. #define        dumprIDEnd        (**MyShell).Proc[ProcID].int1
  94. #define        checkT            (**MyShell).Proc[ProcID].int2
  95. #define        dumprTypes        (**MyShell).Proc[ProcID].bflags.f0
  96. #define        dumprIDs        (**MyShell).Proc[ProcID].bflags.f1
  97. #define        dumprData        (**MyShell).Proc[ProcID].bflags.f2
  98.  
  99.  
  100. /*******************************************************************/
  101.  
  102. void        dumprDumpRes( WHandle ShellWh, int16 ProcID, OsType theType,
  103.                  Handle handle )
  104. {
  105.     LoadResource( handle );
  106.     
  107.     switch( theType )
  108.         {
  109.         case    'ALRT'    :    DumpALRT( ShellWh, ProcID, handle );    break;
  110.         case    'BNDL'    :    DumpBNDL( ShellWh, ProcID, handle );    break;
  111.         case    'CNTL'    :    DumpCNTL( ShellWh, ProcID, handle );    break;
  112.         case    'DITL'    :    DumpDITL( ShellWh, ProcID, handle );    break;
  113.         case    'DLOG'    :    DumpDLOG( ShellWh, ProcID, handle );    break;
  114.         case    'FREF'    :    DumpFREF( ShellWh, ProcID, handle );    break;
  115.         case    'MENU'    :    DumpMENU( ShellWh, ProcID, handle );    break;
  116.         case    'STR '    :    DumpSTR( ShellWh, ProcID, handle );        break;
  117.         case    'STR#'    :    DumpSTRP( ShellWh, ProcID, handle );    break;
  118.         case    'WIND'    :    DumpWIND( ShellWh, ProcID, handle );    break;
  119. /*
  120.  *    For expansion
  121.  *
  122.         case    'XXXX'    :    DumpXXXX( ShellWh, ProcID, handle );    break;
  123.  */        
  124.         default:    DumpGNRL( ShellWh, ProcID, handle, theType );    break;
  125.         }
  126.         
  127.     ReleaseResource( handle );
  128. }        
  129.  
  130. /*******************************************************************/
  131.  
  132. void        dumprDumpType( WHandle ShellWh, int16 ProcID, OsType theType,
  133.                  int16 numRes )
  134. {
  135. OsType        aType;
  136. Boolean        dropOut = FALSE;
  137. int16        resID;
  138. Handle        h;
  139. char        str[ 64 ];
  140. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  141.  
  142.     while( --numRes && !dropOut && !UserAbort() )
  143.         {
  144.         h = Get1IndResource( theType, numRes );
  145.         
  146.         if( h )
  147.             {
  148.             GetResInfo( h, &resID, &aType, str );
  149.             
  150.             if( checkT == 2 )
  151.                 {
  152.                 if( resID < dumprIDStart )
  153.                     continue;
  154.                 else if( resID > dumprIDEnd )
  155.                         continue;
  156.                 }
  157.             else if( checkT == 1 )
  158.                 if( resID != dumprIDStart )
  159.                     continue;
  160.             
  161.             dumprDumpRes( ShellWh, ProcID, theType, h );
  162.             }
  163.         if( UserAbort() )
  164.             dropOut = TRUE;
  165.         }
  166. }
  167.  
  168. /*******************************************************************/
  169.  
  170. void        dumprDumpName( WHandle ShellWh, int16 ProcID, 
  171.                  OsType theType, char *theName )
  172. {
  173. OsType        aType;
  174. Handle        h;
  175. char        str[ 64 ];
  176. int16        resID;
  177. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  178.  
  179.     strcpy( str, theName );
  180.     CtoPstr( str );
  181.     h = Get1NamedResource( theType, str );
  182.     
  183.     if( h )
  184.         {
  185.         GetResInfo( h, &resID, &aType, str );
  186.     
  187.         if( checkT == 2 )
  188.             {
  189.             if( resID < dumprIDStart )
  190.                 return;
  191.             else if( resID > dumprIDEnd )
  192.                     return;
  193.             }
  194.         else if( checkT == 1 )
  195.             if( resID != dumprIDStart )
  196.                 return;
  197.             
  198.         dumprDumpRes( ShellWh, ProcID, theType, h );
  199.         }
  200. }
  201.  
  202. /*******************************************************************/
  203.  
  204. void        DUMPRCallBack( WHandle ShellWh, int16 ProcID, char *path,
  205.                 char *last, pathType what, int16 vRefNum, int32 dirID )
  206. {
  207. char        str[ 64 ];
  208. OSErr        err;
  209. int16        refNum, currFile, numTypes, numRes, resID, resFileWasOpen = FALSE;
  210. OsType        theType, aType;
  211. Handle        h;
  212. Boolean        dropOut = FALSE;
  213. FInfo        finder;
  214. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  215.  
  216.     if( what == pathIsFile )
  217.         {
  218.         strcpy( str, last );
  219.         CtoPstr( str );
  220.         
  221.         err = HSetVol( NULL, vRefNum, dirID );
  222.         
  223.         if( err )
  224.             return;
  225.             
  226.         err = HGetFInfo( vRefNum, dirID, str, &finder );
  227.  
  228.         currFile = CurResFile();
  229.         if( ResFileOpen( last, vRefNum, dirID, &refNum ) )
  230.             resFileWasOpen = TRUE;
  231.         else
  232.             refNum = OpenResFile( str );
  233.         
  234.         if( refNum != (-1) )
  235.             {
  236.             procPrintf( ShellWh, ProcID, "%s\n", last );
  237.             
  238.             TypeToStr( finder.fdType, str );
  239.             procPrintf( ShellWh, ProcID, "%s", str );
  240.             TypeToStr( finder.fdCreator, str );
  241.             procPrintf( ShellWh, ProcID, "%s\n\n", str );
  242.             
  243.             UseResFile( refNum );
  244.             SetResLoad( FALSE );
  245.             numTypes = Count1Types() + 1;
  246.             
  247.             while( --numTypes && !dropOut && !UserAbort() )
  248.                 {
  249.                 Get1IndType( &theType, numTypes );    /* What type is this ? */
  250.                 numRes = Count1Resources( theType ) + 1;
  251.                 
  252.                 if( dumprResType && (dumprResType != theType ) )
  253.                     continue;
  254.                                         
  255.                 if( *dumpResName )
  256.                     dumprDumpName( ShellWh, ProcID, theType, dumpResName );
  257.                 else
  258.                     dumprDumpType( ShellWh, ProcID, theType, numRes );
  259.                 }
  260.                 
  261.             if( !resFileWasOpen )
  262.                 CloseResFile( refNum );
  263.                 
  264.             SetResLoad( TRUE );
  265.             UseResFile( currFile );
  266.             }
  267.         else if( (err = ResError() ||  refNum == (-1)) && (err != eofErr) )
  268.             procPrintf( ShellWh, ProcID, "dumpr : error openning file %s (%d)\n", 
  269.                 last, err );
  270.         }
  271. }
  272.  
  273. /*******************************************************************/
  274.  
  275. void        DUMPRFile( WHandle ShellWh, int16 ProcID, char *argument )
  276. {
  277. ShellWindRec    **MyShell;
  278.  
  279.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  280.  
  281.     ExpandPath( ShellWh, ProcID, argument, (ProcPtr) DUMPRCallBack,
  282.             (**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
  283.  
  284.     ResetShellPWD( ShellWh );
  285. }
  286.  
  287. /*******************************************************************/
  288.  
  289. Boolean            DoDUMPR( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  290.                     char *string )
  291. {
  292. int16            i, argc;
  293. char            *cp, argument[ 256 ];
  294. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  295.  
  296.     switch( ProcToken )
  297.         {
  298.         case    PROC_INIT    :
  299.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  300.             break;
  301.             
  302.         case    PROC_TERM    :
  303.         case    PROC_BREAK    :
  304.             /* Tell the shell that we're done */
  305.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  306.             /* Turn ourself off */
  307.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  308.             break;
  309.             
  310.         case    PROC_STDIN    :
  311.             if( (**MyShell).Proc[ ProcID ].flags )
  312.                 {
  313.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  314.  
  315.                 /* get arguments */
  316.                 argc = (**MyShell).Proc[ ProcID ].argc;
  317.                 
  318.                 dumprTypes        = TRUE;
  319.                 dumprIDs        = TRUE;
  320.                 dumprData        = TRUE;
  321.                 checkT            = 0;
  322.                 dumprIDStart    = 0;
  323.                 dumprIDEnd        = 0;
  324.                 dumprResType    = 0L;        /* no type specifier */
  325.                 *dumpResName    = '\0';
  326.                 
  327.                 for( i = 1; i < argc; i++ )
  328.                     {
  329.                     GetArgv( ShellWh, ProcID, i, argument );
  330.                     cp = argument;
  331.         
  332.                     if( *cp++ == '-' )
  333.                         while( *cp )
  334.                             switch( *cp++ )
  335.                                 {
  336.                                 case    'n'    :    /* Name */
  337.                                     i++;
  338.                                     GetArgv( ShellWh, ProcID, i, dumpResName );
  339.                                     break;
  340.  
  341.                                 case    'i'    :    /* id's */
  342.                                     i++;
  343.                                     if( i < argc )
  344.                                         {
  345.                                         char    *cp, nc, temp[ 64 ], num[ 64 ];
  346.                                         int32    lnum;
  347.                                         
  348.                                         GetArgv( ShellWh, ProcID, i, temp );
  349.                                         
  350.                                         cp = temp;
  351.                                         while( *cp && (*cp != ',') )
  352.                                             cp++;
  353.                                         
  354.                                         nc = *cp;
  355.                                         
  356.                                         if( *cp )
  357.                                             *cp = '\0';
  358.                                         
  359.                                         CtoPstr( temp );
  360.                                         StringToNum( temp, &lnum );
  361.                                         dumprIDStart = (int16) lnum;
  362.                                         checkT++;
  363.  
  364.                                         if( nc )
  365.                                             {
  366.                                             cp++;
  367.                                             CtoPstr( cp );
  368.                                             StringToNum( cp, &lnum );
  369.                                             dumprIDEnd = (int16) lnum;
  370.                                             checkT++;
  371.                                             }
  372.                                         }
  373.                                     break;
  374.  
  375.                                 case    't'    :        /* Type */
  376.                                     i++;
  377.                                     if( i < argc )
  378.                                         {
  379.                                         char    temp[ 256 ];
  380.                                         
  381.                                         GetArgv( ShellWh, ProcID, i, temp );
  382.                                         dumprResType = StrToType( temp );
  383.                                         }
  384.                                     break;
  385.                                 }
  386.                     }
  387.  
  388.                 for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
  389.                     {
  390.                     GetArgv( ShellWh, ProcID, i, argument );
  391.                     if( *argument != '-' )
  392.                         DUMPRFile( ShellWh, ProcID, argument );
  393.                     else
  394.                         switch( argument[ 1 ] )
  395.                             {
  396.                             case    'n'    :
  397.                             case    'i'    :
  398.                             case    't'    :
  399.                                 i++;
  400.                                 break;
  401.                             }
  402.                     }
  403.  
  404.                 /* Tell the shell that we're done */
  405.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  406.                 
  407.                 /* Turn ourself off */
  408.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  409.                 return( FALSE );
  410.                 }
  411.         }
  412. }
  413.